const pageMixin = {
  data () {
    return {
      listMode: true,
      ids: [],
      ckAll: false,
      searchStr: '',
      total: 0,
      page: 1,
      pageSize: 30,
      list: []
    }
  },
  methods: {
    handleChangeMode (listMode) {
      this.listMode = listMode
      this.pageSize = this.listMode ? 10 : 8
    },
    onPageChange (p) {
      this.page = p.page
      this.pageSize = p.pageSize
      this.search()
    },
    handleSearch (searchStr) {
      this.searchStr = searchStr
      this.search()
    },
    search () {
    },
    getList () {
      return JSON.parse(JSON.stringify(this.list))
    },
    checkIds (callback, confirmInfo) {
      if (this.ids.length === 0) {
        this.$warning({ title: '请选择要操作的数据' })
        return
      }
      this.confirm(() => {
        callback(this.ids)
      }, confirmInfo || '确定要删除这些数据么')
    },
    ckAllChange (e) {
      this.list.forEach(t => {
        t.ck = e.target.checked
      })
    },
    ckChange () {
      this.ckAll = this.list.every(t => {
        return t.ck
      })
    }
  }
}

export {
  pageMixin
}
